package com.yunhui.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunhui.entity.RouteXx;
import com.yunhui.mapper.RouteXxMapper;
import com.yunhui.service.RouteXxService;

import com.yunhui.util.PageSupport;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  行程详细的业务处理的层实现类
 * </p>
 *
 * @author WGH
 * @since 2019-12-09
 */
@Service
public class RouteXxServiceImpl extends ServiceImpl<RouteXxMapper, RouteXx> implements RouteXxService {


    @Resource
    RouteXxMapper routeXxMapper;

    /**
     * 添加详情
     * @param routeXx
     * @return
     */
    @Override
    public int insect(RouteXx routeXx) {
        return routeXxMapper.insert(routeXx);
    }

    /**
     * 根据基本详情外键查询
     * 根据顺序字段排序Asc正序
     * @param id
     * @return
     */
    @Override
    public List<RouteXx> getListByJbId(Integer id) {
        List<RouteXx> list=null;
        QueryWrapper<RouteXx> qw=new QueryWrapper<RouteXx>();
        qw.eq("jbId",id);
        qw.orderByAsc("orderTime");
        try {
            list=routeXxMapper.selectList(qw);
        }catch(Exception e){
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 根据jbid ，title 分页查询
     * @param jbId
     * @param title
     * @param page
     * @return
     */
    @Override
    public List<RouteXx> getListByIdTitlePage(Integer jbId, String title, PageSupport page) {
        List<RouteXx> list=null;
        try {
            list=routeXxMapper.getListByIdTitlePage(jbId,title,(page.getCurrentPageNo()-1)*page.getPageSize(),page.getPageSize());
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 根据jbid ，title 查询总数
     * @param jbId
     * @param title
     * @return
     */
    @Override
    public int getCount(Integer jbId, String title) {
        int num=0;
        try {
            num=routeXxMapper.getCount(jbId, title);
        }catch (Exception e){
            e.printStackTrace();
        }
        return num;
    }


    /**
     * 根据Id删除
     * @param id
     * @return
     */
    @Override
    public int deleteById(Integer id) {
        int num=0;
        try {
            num=routeXxMapper.deleteById(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return num;
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public RouteXx selectById(Integer id) {
        RouteXx routeXx =null;

        try {
            routeXx=routeXxMapper.selectById(id);
        }catch (Exception e){
            e.printStackTrace();
        }

        return routeXx;
    }

    /**
     * 根据id修改
     * @param routeXx
     * @return
     */
    @Override
    public int updateXx(RouteXx routeXx) {
        int  num=0;
        try {
            num=routeXxMapper.updateById(routeXx);
        }catch (Exception e){
            e.printStackTrace();
        }
        return num;
    }


}
